using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Business.Entities.Config;
using OR.Reuse.Reflection;

namespace OR.Lazarus.Business.Entities.Config.Lazarus
{
	/// <summary>
	/// 
	/// </summary>
   public class ClassReferenceDetail : EntityBase
   {
		protected System.String mName;
		protected System.String mAssembly;
		protected System.String mClass;
		protected string mDescription;

		public ClassReferenceDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Assembly
		{
			get
			{
				return ( mAssembly );
			}
			set
			{
				mAssembly = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Class
		{
			get
			{
				return ( mClass );
			}
			set
			{
				mClass = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mAssembly = DataUtility.GetString( pSource, "assembly" );
			mClass = DataUtility.GetString( pSource, "class" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lcfg:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lcfg", "class-reference", "http://schemas.icitadel.com/Lazarus/Config.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mAssembly ) )
			{
				vNewElement.SetAttribute( "assembly", mAssembly );
			}
					
			if ( !String.IsNullOrEmpty( mClass ) )
			{
				vNewElement.SetAttribute( "class", mClass );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lcfg", "description", "http://schemas.icitadel.com/Lazarus/Config.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.ClassReferenceDetail v_oReturn = new Derived.ClassReferenceDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Assembly = mAssembly;
			v_oReturn.Class = mClass;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual TYPE GetInstanceType<TYPE>()
		{
			TYPE vReturn = ( TYPE )AssemblyUtility.GetInstance( mAssembly, mClass );

			return ( vReturn );
		}

		public virtual Derived.ClassReferenceDetail CloneTyped()
		{
			return ( ( Derived.ClassReferenceDetail )this.Clone() );
		}
   }
}
   